//1. 公用样式
require('../../assets/css/index.less');
require('../../assets/css/basic.less');
require('../../assets/fonts/iconfont.css');

//2. 当前页面样式
require('./my.less');

//3. 公用js
let dom = require('../../utils/dom.js');
let local = require('../../utils/local.js');
let https = require('../../utils/https.js');

//4. 当前页面的js
// console.log(dom);

dom.ready(function(){
    //自己的写页面js
    dom.bMeun('my');
    quitBtn.addEventListener('click', function () { 
        local.clear();
        window.location.href='login.html'
    });
    // 退出登录
    goBtn.addEventListener('click', function () { 
        // window.history.go(-1);
        window.location.href = 'pepole.html';
    });
    getUserClock();
    // 获取用户个人信息,并渲染数据到my页面
    function getInfo() { 
        https.get('api/user/info', {}, function (res) {
          if (res.errno == 0) { 
              console.log(res);
                local.set('userData', res.data);
                vatar.src = res.data.imgUrl?' http://47.96.154.185:3701' + res.data.imgUrl:require('../../assets/imgs/headerPic.jpg');
                nickNameTxt.innerHTML = res.data.nickName;
              signTxt.innerHTML = res.data.sign;
            clockNum.innerHTML = res.data.clockCount;
            }
         });
    }
    getInfo();

    // 获取打卡信息
  function getUserClock() { 
    https.get('/api/user/clockInInfo', {}, function (res) {
      // console.log(res);
      if (res.errno == 0) {
        clockBtn.innerHTML=res.data.isClockIn?'今日已打卡':'今日打卡'
      } else { 
        console.log('获取信息失败');
      }
     });  
  }

  // 打卡功能绑定点击事件
  clockBtn.addEventListener('click', function () { 
    https.post('/api/user/clockIn', {}, function (res) {
      // console.log(res);
      if (res.errno == -1) {//打卡失败
        alert(res.message);
        getUserClock();
      } else { 
        alert('打卡成功');//打卡成功
      }
     });
  });

  sportData.addEventListener('click', function () { 
    window.location.href = 'sportData.html';
  });
})
